<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<!-- <div class="search-field">
    
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div> -->
<div id="searchF" class="search-field">
	<span class="field-cont">
        <span class="field-cont-title">商品名</span>
        <input type="text" class="summer-input" id="goodsName"/>
        <input type="hidden" class="summer-input" id="userId"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">商品平台类型</span>
        <input type="text" id="spuPlatform" name="spuPlatform" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[20]']"/> 
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">商品分类</span>
        <input type="text" id="categoryId" name="categoryId" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[500]']"/> 
    </span><br/>
   
     <span class="field-cont">
        <span class="field-cont-title">是否爆款</span>
        <input type="text" class="summer-input" id="isHot"/>
    </span><br/>
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
        <a id="delSetedGoods" class="btn btn-primary  wave distance-right">删除商品</a>
    </span>
    </div>
<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="10%">
	    <col width="30%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="25%">
	    <thead>
		     <tr>
		    <th><div class="summer-datagrid-cell"><input type="checkbox" id="addBatchAll"></div></th>
		    <th><div class="summer-datagrid-cell">名称</div></th>
		    <th><div class="summer-datagrid-cell">图片</div></th>
		    <th><div class="summer-datagrid-cell">类型</div></th>
		    <th><div class="summer-datagrid-cell">分类</div></th>
		    <th><div class="summer-datagrid-cell">价钱（原价、券后价、佣金数）</div></th>
		    <th><div class="summer-datagrid-cell">时间</div></th>
			 </tr>
	    </thead>
    </table>  
</div>

<script>
	//请求url
	var CONST_URL = {
		GET_GOODS: basePath + '${common_url}getGoods',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	DEL_SETED_GOODS: basePath + "${common_url}delSetedGoods",
	   	INIT_MAIN: basePath + "${common_url}init",
	   	GET_GOODS_CATEGORY: basePath + "${common_url}getGoodsCategory"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAdd']
		});
        //勾选全部
        $('#addBatchAll').on('click',checkAll);
		$("#userId").val(${userId});
		
		//下拉初始化
   	 	$('#isHot').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_IS_HOT'
        });
   	 	$('#categoryId').combobox({
            url : CONST_URL.GET_GOODS_CATEGORY, 
            valueField : 'id',
            async:false,
            textField : 'name'
        });
   	 	$('#spuPlatform').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_SPU_PLATFORM'
        });
   	 //下拉列表初始化，上传类型
   		$('#type').combobox({
  	       async:false,
           valueField : 'code',
           textField : 'name',
           url : COMMON_URL.getCode + '?type=T_DM_T_YWYM_TIMER_TYPE'
   		});
        // 查询按钮
        $('#search').on('click', reloadTable);
        //返回按钮
   	    $('#goBack').on('click',backMain);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#goodsName').val('');
			$('#spuPlatform').combobox('clear'),
			$('#categoryId').combobox('clear'),
			$('#isHot').combobox('clear')
        	reloadTable();
        });
        
       createTable();
        
        //删除
		$('#delSetedGoods').on('click', function() {
			var spuId = $("input[name='spuId']:checked").serialize(),
			userId = $("#userId").val();
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL_SETED_GOODS+"?spuId="+spuId+"&userId="+userId,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
    });
    
    //勾选全部
    function checkAll(){
		 $("[name='id']").attr("checked",'true');//全选 
	}
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload', {
			ajax : {
				param : {
					"goodsName": trimSpace($('#goodsName').val()),
					"spuPlatform":$('#spuPlatform').combobox('getValue'),
					"categoryId":$('#categoryId').combobox('getValue'),
					"isHot":$('#isHot').combobox('getValue'),
					"userId": trimSpace($('#userId').val())
				}
			}
		});
	}
    
	//创建表格
	function createTable() {
		$('#dataList')
				.datagrid(
						{
							ajax : {
								url : CONST_URL.GET_GOODS,
								param : {	
									"goodsName": trimSpace($('#goodsName').val()),
									"spuPlatform":$('#spuPlatform').combobox('getValue'),
									"categoryId":$('#categoryId').combobox('getValue'),
									"isHot":$('#isHot').combobox('getValue'),
									"userId": trimSpace($('#userId').val())
								},
								success : function(data) { //成功 
									alert("Data Saved: " + msg);
								}
							},
							columns : [
									{
										render : function(rowData){
											return '<input type="checkbox" id="spuId" name="spuId" value="'+rowData.id+'">';
										}
									},
									{
										field : 'goodsName'
									},
									{
										field: 'mainImageUrl',
										render : function(rowData){
											return '<img width="100" height="100" src="'+rowData.mainImageUrl+'">';
										}
									},
									{
										field : 'spuPlatform'
									},
									{
										field : 'categoryId'
									},
									{
										render : function(rowData){
											return '<p>原价：'+rowData.wlPrice+'</p><br/>'
												  +'<p>券后价：'+rowData.conPrice+'</p><br/>'
												  +'<p>佣金：'+rowData.wlCommission+'</p>';
										}
									},
									{
										field : 'createTime'
									}
							]
						});
	}

	//返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
   
</script>
</body>
</html>